package com.abu.edums.controller;

import com.abu.edums.mapper.CourseMapper;
import com.abu.pojo.demo.ChapterDTO;
import com.abu.utils.Resp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * 测试使用的controller
 */
@RestController
@RequestMapping("/demo/course")
public class DemoController {


    @Autowired
    private CourseMapper courseMapper;

    @GetMapping("findAllChapterAndVideo")
    public Resp findAllChapterAndVideo(@RequestParam("courseId") String courseId) {
        List<ChapterDTO> chapterDTOS = this.courseMapper.querAllChapterAndVideos(courseId);
        if (CollectionUtils.isEmpty(chapterDTOS)) {
            return Resp.error();
        }
        return Resp.ok().data("chapterVideoList", chapterDTOS);
    }
}
